﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 动画Viewer 数据结构体
/// </summary>
public class AnimClipInfo
{
    /// <summary>
    /// 约定的每秒帧数
    /// </summary>
    private const int AnimFrame = 30;
    /// <summary>
    /// 动画名
    /// </summary>
    private string mAnimName = string.Empty;
    public string AnimName
    {
        get { return mAnimName; }
    }
    /// <summary>
    /// 动画总时间
    /// </summary>
    private float mAnimTime = 0;
    public float AnimTime
    {
        get { return mAnimTime; }
    }
    /// <summary>
    /// 动画总帧数
    /// </summary>
    private int mFrameCount = 0;
    public int FrameCount
    {
        get { return mFrameCount; }
    }
    /// <summary>
    /// 一帧时间
    /// </summary>
    private int mFrameRatio = 0;
    public int FrameRatio
    {
        get { return mFrameRatio; }
    }

    public List<FrameInfo> GetFrameList()
    {
        return FrameList;
    }
    /// <summary>
    /// 所有帧信息
    /// </summary>
    private List<FrameInfo> FrameList = new List<FrameInfo>();

    public AnimClipInfo(AnimationClip clipInfo)
    {
        //TODO 
        FrameList.Clear();
        mFrameRatio = Mathf.CeilToInt((1f / 30f) * 1000);
        mAnimName = clipInfo.name;
        mAnimTime = clipInfo.length;
        mFrameCount =Mathf.CeilToInt( mAnimTime * AnimFrame);
        var percent = (1f / mFrameCount);
        for (int i = 0; i < mFrameCount; i++)
        {
            var curFrameTime = (i+1)* percent * mAnimTime;
            var frameInfo = new FrameInfo(AnimName, i + 1, FrameRatio, curFrameTime , curFrameTime / mAnimTime);
            // var frameInfo = new FrameInfo(mAnimName, i+1,mFrameRatio,mFrameRatio*(i+1));
            FrameList.Add(frameInfo);
        }
    }
}
